package Basiques;

import java.io.Serializable;
import java.util.ArrayList;

import Persistance.TMain;
import Persistance.TTournoi;
import PersistanceBase.PrimaryKey;
import PersistanceBase.TableGenerique;
import PersistanceBase.TableName;
import android.content.ContentValues;
import android.database.Cursor;
@TableName(Name="T_MAIN")
public class TMainBasique extends TableGenerique implements Serializable
{
	private static final long serialVersionUID = 1L;
	protected String carte;

	protected Integer gagne;

	protected Integer joue;

	protected String kicker;

	@PrimaryKey(AutoIncrement="True")
	protected Integer num;

	protected Integer stack;

	protected Integer trnNum;


	public String getCarte()
	{
		return carte;
	}

	public void setCarte(String value)
	{
		carte = value;
	}

	public Integer getGagne()
	{
		return gagne;
	}

	public void setGagne(Integer value)
	{
		gagne = value;
	}

	public Integer getJoue()
	{
		return joue;
	}

	public void setJoue(Integer value)
	{
		joue = value;
	}

	public String getKicker()
	{
		return kicker;
	}

	public void setKicker(String value)
	{
		kicker = value;
	}

	public Integer getNum()
	{
		return num;
	}

	public void setNum(Integer value)
	{
		num = value;
	}

	public Integer getStack()
	{
		return stack;
	}

	public void setStack(Integer value)
	{
		stack = value;
	}

	public Integer getTrnNum()
	{
		return trnNum;
	}

	public void setTrnNum(Integer value)
	{
		trnNum = value;
	}

	@Override
	public ContentValues GetContentValues(boolean avecPrimaryKey){
		ContentValues values = new ContentValues(12);
		if (getDateCreation() != null)
			values.put("DATE_CREATION", TableGenerique.DATE_FORMAT_ISO.format(getDateCreation()));
		if (getDateModif() != null)
			values.put("DATE_MODIF", TableGenerique.DATE_FORMAT_ISO.format(getDateModif()));
		if (getCarte() != null)
			values.put("MAI_CARTE", getCarte());
		if (getGagne() != null)
			values.put("MAI_GAGNE", getGagne());
		if (getJoue() != null)
			values.put("MAI_JOUE", getJoue());
		if (getKicker() != null)
			values.put("MAI_KICKER", getKicker());
		if (getNum() != null)
			values.put("MAI_NUM", getNum());
		if (getStack() != null)
			values.put("MAI_STACK", getStack());
		if (getTrnNum() != null)
			values.put("MAI_TRN_NUM", getTrnNum());
		if (getUserCreation() != null)
			values.put("USER_CREATION", getUserCreation());
		if (getUserModif() != null)
			values.put("USER_MODIF", getUserModif());
		if (getVersion() != null)
			values.put("VERSION", getVersion());
		return values;
	}

	@Override
	public String GenerationClauseWhere(boolean primaryKeyOnly)
	{
		ArrayList<String> listeMots = new ArrayList<String>(12);
		if (getNum() != null)
		{
			listeMots.add(String.format("MAI_NUM = %s ", getNum()));
		}
		if (primaryKeyOnly)
			return TableGenerique.concatWith(listeMots, " and ");
		if (getDateCreation() != null)
		{
			listeMots.add(String.format("DATE_CREATION = '%s' ", DATE_FORMAT_ISO.format(getDateCreation())));
		}
		if (getDateModif() != null)
		{
			listeMots.add(String.format("DATE_MODIF = '%s' ", DATE_FORMAT_ISO.format(getDateModif())));
		}
		if (getCarte() != null)
		{
			listeMots.add(String.format("MAI_CARTE = '%s' ", getCarte().replace("'", "''")));
		}
		if (getGagne() != null)
		{
			listeMots.add(String.format("MAI_GAGNE = %s ", getGagne()));
		}
		if (getJoue() != null)
		{
			listeMots.add(String.format("MAI_JOUE = %s ", getJoue()));
		}
		if (getKicker() != null)
		{
			listeMots.add(String.format("MAI_KICKER = '%s' ", getKicker().replace("'", "''")));
		}
		if (getStack() != null)
		{
			listeMots.add(String.format("MAI_STACK = %s ", getStack()));
		}
		if (getTrnNum() != null)
		{
			listeMots.add(String.format("MAI_TRN_NUM = %s ", getTrnNum()));
		}
		if (getUserCreation() != null)
		{
			listeMots.add(String.format("USER_CREATION = '%s' ", getUserCreation().replace("'", "''")));
		}
		if (getUserModif() != null)
		{
			listeMots.add(String.format("USER_MODIF = '%s' ", getUserModif().replace("'", "''")));
		}
		if (getVersion() != null)
		{
			listeMots.add(String.format("VERSION = %s ", getVersion()));
		}
		return TableGenerique.concatWith(listeMots, " and ");
	}
	@Override
	public TMain getObjetFromDataBase(Cursor c)
	{
		TMain objetRetour = new TMain();
		int colonneIndex = 0;
		colonneIndex = c.getColumnIndex("DATE_CREATION");
		if (c.isNull(colonneIndex))
			objetRetour.DateCreation = null;
		else
			objetRetour.DateCreation = TableGenerique.dataBaseFieldToDate(colonneIndex, c);

		colonneIndex = c.getColumnIndex("DATE_MODIF");
		if (c.isNull(colonneIndex))
			objetRetour.DateModif = null;
		else
			objetRetour.DateModif = TableGenerique.dataBaseFieldToDate(colonneIndex, c);

		colonneIndex = c.getColumnIndex("MAI_CARTE");
		if (c.isNull(colonneIndex))
			objetRetour.setCarte(null);
		else
			objetRetour.setCarte(c.getString(colonneIndex));

		colonneIndex = c.getColumnIndex("MAI_GAGNE");
		if (c.isNull(colonneIndex))
			objetRetour.setGagne(null);
		else
			objetRetour.setGagne(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("MAI_JOUE");
		if (c.isNull(colonneIndex))
			objetRetour.setJoue(null);
		else
			objetRetour.setJoue(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("MAI_KICKER");
		if (c.isNull(colonneIndex))
			objetRetour.setKicker(null);
		else
			objetRetour.setKicker(c.getString(colonneIndex));

		colonneIndex = c.getColumnIndex("MAI_NUM");
		if (c.isNull(colonneIndex))
			objetRetour.setNum(null);
		else
			objetRetour.setNum(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("MAI_STACK");
		if (c.isNull(colonneIndex))
			objetRetour.setStack(null);
		else
			objetRetour.setStack(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("MAI_TRN_NUM");
		if (c.isNull(colonneIndex))
			objetRetour.setTrnNum(null);
		else
			objetRetour.setTrnNum(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("USER_CREATION");
		if (c.isNull(colonneIndex))
			objetRetour.UserCreation = null;
		else
			objetRetour.UserCreation = c.getString(colonneIndex);

		colonneIndex = c.getColumnIndex("USER_MODIF");
		if (c.isNull(colonneIndex))
			objetRetour.UserModif = null;
		else
			objetRetour.UserModif = c.getString(colonneIndex);

		colonneIndex = c.getColumnIndex("VERSION");
		if (c.isNull(colonneIndex))
			objetRetour.Version = null;
		else
			objetRetour.Version = c.getInt(colonneIndex);

		return objetRetour;
	}


	private TTournoi _tournoi;

	public TTournoi getTournoi()
	{
		return _tournoi;
	}

	public void setTournoi(TTournoi value)
	{
		_tournoi = value;
	}

	public void initialiseTournoi ()
	{
		if (_tournoi != null)
			return;
		TTournoi critere = new TTournoi ();
		critere.setNum(getTrnNum());
		_tournoi = (TTournoi) TTournoi.select (critere);
	}
}
